package hibernate;

import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

import comun.*;
 
public class HibernateUtil
{
    private static final SessionFactory sessionFactory;
    static
    {
        try
        {
       	 AnnotationConfiguration config = new AnnotationConfiguration();
       	 config.setProperty("hibernate.dialect", "org.hibernate.dialect.SQLServerDialect");
         config.setProperty("hibernate.connection.driver_class", "net.sourceforge.jtds.jdbc.Driver");
         config.setProperty("hibernate.connection.url", "jdbc:jtds:sqlserver://192.168.56.101/tpcorreolv");
         config.setProperty("hibernate.connection.username", "poo");
         config.setProperty("hibernate.connection.password", "poo");
         config.setProperty("hibernate.connection.pool_size", "1");
         config.setProperty("hibernate.connection.autocommit", "false");
        // config.setProperty("hibernate.cache.provider_class", "org.hibernate.cache.NoCacheProvider");
         config.setProperty("hibernate.hbm2ddl.auto", "update");
         config.setProperty("hibernate.show_sql", "true");
         config.setProperty("hibernate.transaction.factory_class", "org.hibernate.transaction.JDBCTransactionFactory");
         config.setProperty("hibernate.current_session_context_class", "thread");
         
         // agregar tablas
         config.addAnnotatedClass(CasillaCorreo.class);
         config.addAnnotatedClass(Mensaje.class);
         config.addAnnotatedClass(Usuario.class);
         config.addAnnotatedClass(Inbox.class);
         config.addAnnotatedClass(OficinaCorreo.class);
         config.addAnnotatedClass(RelacionConfianza.class);         
         
         sessionFactory = config.buildSessionFactory();
          }

        catch (Throwable ex)
        {
            System.err.println("Initial SessionFactory creation failed." + ex);
            throw new ExceptionInInitializerError(ex);
        }
    }
 
    public static SessionFactory getSessionFactory()
    {
        return sessionFactory;
    }
}
